package com.finalProject;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.NetworkOnMainThreadException;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.content.SharedPreferences;
import android.widget.SimpleAdapter;
import android.widget.Toast;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.ListFragment;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * author: Jimmmy Smile
 * date: 2021-06-10 20:06::06
 * positioan: com.finalProject
 * e-mail:jimmysmileltl@163.com
 **/
//implements Runnable, AdapterView.OnItemClickListener,AdapterView.OnItemLongClickListener {
public  class Fragment_First extends ListFragment implements  AdapterView.OnItemClickListener,AdapterView.OnItemLongClickListener {
    private static final String TAG = "fragment";
    AdapterOf_Income adapter;
    List<Income> list;
    ListView listView;
    //Income data;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        incomeTop100_Spider_and_Show income=new incomeTop100_Spider_and_Show();
       // list=income.getList();
        Income hp1 = new Income("排名", "城市", "元/年");
        list.add(hp1);
        adapter=new AdapterOf_Income(getContext(),
                R.layout.list_item_income,
                list);
        setListAdapter(adapter);


    }

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_first, container, false);
    }


    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        Log.i(TAG, "onItemClick: ccccccccccc");
        Object itemAtPosition = getListView().getItemAtPosition(position);
        Income temp = (Income) itemAtPosition;
        String city = temp.getCity();
        String income = temp.getIncome();
        String order=temp.getOrder();
        Log.i(TAG, "run:点了一下 " + order + "===>>" + city+"===>>"+income);
        Intent intent =new Intent(getActivity(),income_jisuuan.class);
        intent.putExtra("city",city);
        intent.putExtra("income",income);
        intent.putExtra("order",order);
        startActivity(intent);
        Log.i(TAG, "onItemClick: 传输成功");

    }

    @Override
    public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
        Log.i(TAG, "onItemLongClick: 长按position"+String.valueOf(position));
        HousePrice temp = (HousePrice) getListView().getItemAtPosition(position);
        String title=temp.getCity();
        Log.i(TAG, "onItemLongClick: "+temp.getCity());
        //删除操作
        AlertDialog.Builder dialog =new AlertDialog.Builder(getActivity());
        dialog.setTitle("提升！");
        dialog.setMessage("确认是否删除"+title);
        dialog.setPositiveButton("YES", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                list.remove(position);
                adapter.notifyDataSetChanged();
                Log.i(TAG, "onItemLongClick:删除成功 "+title+"   剩余："+list.size());
            }
        });
        dialog.setNegativeButton("CACEL",null);
        dialog.create().show();

        return true;//false 同时长按、短按
    }
}